package com.manage.server.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manage.server.mapper.IncomeMapper;
import com.manage.server.pojo.Income;
import com.manage.server.pojo.QueryIncome;
import com.manage.server.service.IncomeService;
import com.mysql.cj.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zl
 * @since 2021-05-26
 */
@Service
public class IncomeServiceImpl
        extends ServiceImpl<IncomeMapper, Income>
        implements IncomeService {
    @Autowired
    private IncomeMapper incomeMapper;
    /**
     * <p>
     *  获得所有收支实现
     * </p>
     *
     * @author zl
     * @since 2021-05-26
     */
    @Override
    public List<Income> getAllIncome() {
        return incomeMapper.selectList(null);
    }
    /**
     * <p>
     *  更新收支实现
     * </p>
     *
     * @author zl
     * @since 2021-05-26
     * @return
     */
    @Override
    public boolean updateIncome(Income income) {
        return incomeMapper.updateById(income)>0;
    }
    /**
     * <p>
     *  删除收支实现
     * </p>
     *
     * @author zl
     * @since 2021-05-26
     */
    @Override
    public boolean deleteIncomeById(Integer id) {
        return incomeMapper.deleteById(id)>0;
    }
    /**
     * <p>
     *  添加收支实现
     * </p>
     *
     * @author zl
     * @since 2021-05-26
     */
    @Override
    public boolean addIncome(Income income) {
        return incomeMapper.insert(income) > 0;
    }
    /**
     * <p>
     *  根据条件查询收支实现
     * </p>
     *
     * @author zl
     * @since 2021-05-26
     */
    @Override
    public List<Income> getIncomes(QueryIncome queryIncome) {
        QueryWrapper<Income> wrapper = new QueryWrapper<Income>();
        wrapper.eq("rtype", queryIncome.getRtype()).eq("ritem", queryIncome.getRitem()).ge(!StringUtils.isNullOrEmpty(queryIncome.getStartDate()), "rdate", queryIncome.getStartDate()).le(!StringUtils.isNullOrEmpty(queryIncome.getEndDate()), "rdate", queryIncome.getEndDate()).ge(!"null".equals(String.valueOf(queryIncome.getMinBal())), "bal", queryIncome.getMinBal()).le(!"null".equals(String.valueOf(queryIncome.getMaxBal())), "bal", queryIncome.getMaxBal());
        return incomeMapper.selectList(wrapper);
    }

}
